//
//  AdvertCellView.m
//  CCBShop
//
//  Created by lijianhua on 14-11-27.
//  Copyright (c) 2014年 CCB. All rights reserved.
//

#import "AdvertCellView.h"
#import "UIImageView+WebCache.h"
//#import "MainMacro.h"

@implementation AdvertCellView

- (id)initWithFrame:(CGRect)frame advertDictionary:(NSDictionary *)advertDic
{
    self=[super initWithFrame:frame];
    if (self)
    {
        advertDictionary = advertDic;
        
        field = [advertDictionary objectForKey:@"field"]?[advertDictionary objectForKey:@"field"]:@"";
        imgUrl = [advertDictionary objectForKey:@"imgUrl"]?[advertDictionary objectForKey:@"imgUrl"]:@"";
        name = [advertDictionary objectForKey:@"name"]?[advertDictionary objectForKey:@"name"]:@"";
        url = [advertDictionary objectForKey:@"url"]?[advertDictionary objectForKey:@"url"]:@"";
        
//        url = @"http://buy.ccb.com";
        
//        //设置图片视图
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height)];
//        self.imageView.userInteractionEnabled = YES;
//        self.imageView.clipsToBounds = NO;
 //liurg       [self.imageView setImageWithUrl:imgUrl];
        [self addSubview:self.imageView];
        
        self.imageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height)];
        [self.imageButton addTarget:self action:@selector(imagebuttonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.imageButton.backgroundColor = [UIColor clearColor];
        [self addSubview:self.imageButton];
    }
    return self;
}


//**********************test *******************/

- (id)initWithFrameTest:(CGRect)frame advertString:(NSString *)adverStr{
    
    self=[super initWithFrame:frame];
    if (self)
    {
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height)];
        self.imageView.image = [UIImage imageNamed:adverStr];
        self.imageView.layer.cornerRadius = 4.0;
        self.imageView.clipsToBounds = YES;
        self.layer.cornerRadius = 4.0;

        [self addSubview:self.imageView];
        self.imageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height)];
        [self.imageButton addTarget:self action:@selector(imagebuttonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.imageButton.backgroundColor = [UIColor clearColor];
        [self addSubview:self.imageButton];
        
        url = @"http://buy.ccb.com";
        name = @"商城";
    }
    return self;
    
}


- (void)imagebuttonClick:(id)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(advertCellClickWithName:url:)]) {
        [self.delegate advertCellClickWithName:name url:url];
    }
}

//-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    [super touchesBegan:touches withEvent:event];
//    [self performSelector:@selector(touchesBeganAction) withObject:nil afterDelay:0.1];
//    
//    if (self.delegate && [self.delegate respondsToSelector:@selector(advertCellClickWithName:url:)]) {
//        [self.delegate advertCellClickWithName:name url:url];
//    }
//}
//
//-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    [super touchesBegan:touches withEvent:event];
//    [self performSelector:@selector(touchesEndAction) withObject:nil afterDelay:0.4];
//}
//
//-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    [super touchesBegan:touches withEvent:event];
//    [self performSelector:@selector(touchesEndAction) withObject:nil afterDelay:0.1];
//    
//}
//
//-(void)touchesBeganAction
//{
//    //    self.alpha = 0.5;
//}
//
//-(void)touchesEndAction
//{
//    //    self.alpha = 1;
//}
@end
